package com.edie.customview.modular.mymvpusebase;

import android.util.Log;
import android.widget.Toast;

import com.edie.customview.CustomApplication;
import com.edie.customview.basemvp.BasePresenter;
import com.edie.customview.modular.mymvp.MyMvpContract;

import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * edie create on 2018/7/19
 */
public class MyMvpDemoPresenterImpl extends BasePresenter<MyMvpDemoContract.IDemoView> implements MyMvpDemoContract.IDemoPresenter {
    private static final String TAG = "MyMvpDemoPresenterImpl";
    private MyMvpDemoContract.IMyMvpModel mMyMvpModel;

    public MyMvpDemoPresenterImpl(MyMvpDemoContract.IDemoView view) {
        super(view);
        mMyMvpModel = new MyMvpDemoModelImpl();
    }

    @Override
    public void loadMsg(String msgId) {
        mMyMvpModel.loadMsg(msgId)
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {
                        if (mViewRf != null && mViewRf.get() != null) {
                            mViewRf.get().showMsg(s);
                        } else {
                            Log.d(TAG, "onNext: 为空了");
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e(TAG, "onError: ", e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
